export default {
    namespaced: true,
    actions: {
        odd: function (context, value) {
            if (context.state.count % 2 == 0) {
                console.log('action的odd方法被调用了' + context, value);
                context.dispatch('demo', value)

            }
        },
        demo: function (context, value) {
            console.log("我帮odd处理了一些事情然后交给demo2");
            context.dispatch('demo2', value)
        },
        demo2: function (context, value) {
            console.log("我帮demo处理了一些事情o2");
            context.commit('ODD', value);
        },

        waitadd: function (context, value) {
            console.log('action的waitadd方法被调用了' + context, value);
            setTimeout(() => {

                context.commit('WAITADD', value)
            }, 500)


        }
    },
    mutations: {
        //便于区分
        JIA: function (state, value) {
            console.log(state, value);
            state.count += value
        },
        JIAN: function (state, value) {
            console.log(state, value);
            state.count -= value
        },
        ODD: function (state, value) {
            console.log(state, value);
            state.count += value
        },
        WAITADD: function (state, value) {
            console.log(state, value);
            state.count += value
        },


    },
    state: {
        count: 0,
        school: '前端',
        name: 'lili'
    },
    getters: {
        bigSum(state) {
            return state.count * 10
        }
    }
}
